package syn.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * Created by Administrator on 2018\3\4 0004.
 */
public class StudentAspect {
    // 方法执行前
    public void doBefore(JoinPoint jp){
        System.out.println("类名:"+jp.getTarget().getClass().getName());
        System.out.println("方法名："+jp.getSignature().getName());
        //返回参数数组
        System.out.println("开始添加学生："+jp.getArgs()[0]);
    }
    //方法执行后
    public void doAfter(JoinPoint jp){
        System.out.println("类名:"+jp.getTarget().getClass().getName());
        System.out.println("方法名："+jp.getSignature().getName());
        System.out.println("学生添加完成："+jp.getArgs()[0]);
    }
    // 环形切入
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long a=System.currentTimeMillis();
        System.out.println(a);
        Object obj=pjp.proceed();
        long b=System.currentTimeMillis();
        long c=b-a;
        System.out.println("执行方法:"+pjp.getSignature().getName()+"用时"+c);
        return  obj;
    }
    // 在返回之前切入
    public void doAfterReturning(JoinPoint jp){
        System.out.println("返回通知");
    }
    //异常通知
    public void doAfterThrowing(JoinPoint jp,Throwable ex){
        System.out.println("异常通知");
        System.out.println("异常信息："+ex.getMessage());
    }
}
